#include "main.h"

#define EIYLI if (y >= 0 && x >= 0 && y < S_HEIGHT && x < S_WIDTH)

#define PICS1 7

char kuvat1[PICS1][25] = {"data/background.png", "data/adolf.png", "data/teenagegirl.png", "data/members.png", "data/nekrolover.png", "data/darkdestroyer.png", "data/list.png"};

#define SAMPLES 3
char samples[SAMPLES][20] = {"data/glory.ogg", "data/free.ogg", "data/saved.ogg"};

class pissapaska
{
		int x, y, r;
	
		int now;
		
		int aika;
		
		void lataa_kuvat();
		
		SDL_Surface *pics[PICS1];
		
		
				Mix_Chunk *music[SAMPLES];
		SDL_Rect src, dst;
		
		int aikapaska;
	
	public:
		pissapaska();
		void run();
		int kerrat;
		int kerrat2;
};

pissapaska::pissapaska()
{	
	kerrat = 0;
	kerrat2 = 1;
	aika = SDL_GetTicks();
	lataa_kuvat();
}

void pissapaska::run()
{
	
	now = SDL_GetTicks()-aika;
	
	

	
	
	
	SDL_FillRect(screen, NULL, 0);
	
	SDL_BlitSurface(pics[0], NULL, screen, NULL);
	
	dst.y = 0;
	dst.x = (now-8000)/16;
	SDL_BlitSurface(pics[1], NULL, screen, &dst);
	
	dst.y = 0;
	dst.x = (13500-now)/16;
	SDL_BlitSurface(pics[2], NULL, screen, &dst);
	
	
	if (kerrat == 1 && kerrat2 == 1)
	{
		aikapaska = SDL_GetTicks()-aika;	
		kerrat2 = 2 ;
	}
	
	if (kerrat == 2 && kerrat2 == 2)
	{
		aikapaska = SDL_GetTicks()-aika;
		kerrat2++;
	}
	
		
	if (kerrat == 3 && kerrat2 == 3)
	{
		aikapaska = SDL_GetTicks()-aika;
		Mix_Volume(Mix_PlayChannel(-1, music[1], 0),MIX_MAX_VOLUME/2);
		kerrat2++;
	}
	if (kerrat == 4 && kerrat2 == 4)
	{
		aikapaska = SDL_GetTicks()-aika;
		Mix_Volume(Mix_PlayChannel(-1, music[2], 0),MIX_MAX_VOLUME/2);
		kerrat2 = 5;
	}
	if (kerrat == 5 && kerrat2 == 5)
	{

		Mix_Volume(Mix_PlayChannel(-1, music[2], 0),MIX_MAX_VOLUME);
		kerrat2 = 6;
	}
	if (kerrat == 6 && kerrat2 == 6)
	{

		Mix_Volume(Mix_PlayChannel(-1, music[2], 0),MIX_MAX_VOLUME);
		kerrat2++;
	}
	
	
	
	if (kerrat == 1)
	{

		dst.y = 0;
		dst.x = 900 - ((now-aikapaska)/3);
		SDL_BlitSurface(pics[3], NULL, screen, &dst);
	}
	
		
	if (kerrat == 2)
	{

		dst.y = 0;
		dst.x = 900 - ((now-aikapaska)/3);
		SDL_BlitSurface(pics[4], NULL, screen, &dst);
	}
	
	if (kerrat == 3)
	{

		dst.y = 0;
		dst.x = 900 - ((now-aikapaska)/3);
		SDL_BlitSurface(pics[5], NULL, screen, &dst);
	}

	if (kerrat >= 4)
	{

		dst.y = 0;
		if (900 - ((now-aikapaska)/3)>0)
		dst.x = 900 - ((now-aikapaska)/3);
		else
			dst.x = (sin(SDL_GetTicks()/800.)*225)-225;
		

		SDL_BlitSurface(pics[6], NULL, screen, &dst);
	}

}

void pissapaska::lataa_kuvat()
{
	for (int i = 0; i < PICS1; i++)
	{
		pics[i] = SDL_DisplayFormat(IMG_Load(kuvat1[i]));
		SDL_SetColorKey(pics[i], SDL_SRCCOLORKEY, SDL_MapRGB(pics[i]->format, 255, 255, 255));
	}
	
	for (int i = 0; i < SAMPLES; i++)
		music[i] = Mix_LoadWAV(samples[i]);
			
}
